package com.spancer.contentcenter.test.registbean;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.stereotype.Component;

/**
 * author by: mars
 * Date: 2020/10/15 0:22
 * Description:方式5
 * > implements ImportBeanDefinitionRegistrar
 * > 在启动类上添加 @Import()注解
 */
@Component
public class MyCow implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

        RootBeanDefinition rootBeanDefinition = new RootBeanDefinition();
        rootBeanDefinition.setBeanClass(Cow.class);
        registry.registerBeanDefinition("cow",rootBeanDefinition);

    }
}
